<include file="../Public/header_sh.html" />
<script type="text/javascript">
var current_pno = 1;//当前分页数
var ifChangeXY = false;//是否转换统计图XY轴
$(function(){
	//alert(21%8);
	$('#pdesc').blur(
		function(){
			$('#p_list').fadeOut("fast");
		}
		,
		function(){
			$('#pdesc').keyup();
		}
	);
	$('#pdesc').focus( function(){ $(this).keyup(); } );
	$('#pdesc').bind("keyup",function(){
			var current_obj = $(this);
			
			if( $('#p_list').html()!='' ){ 
				var position = current_obj.offset();
				$('#p_list').css({"top":(position.top+23)+"px","left":position.left+"px"});
				$('#p_list').fadeIn("fast");return;
			}
			//alert(2);
			
			//var pdesc_ = jQuery.trim(current_obj.val());
     		$.kajax({      
       			ajx_rtn_type:'JSON',
       			url:"{:U('shanghu://Public/ajxshporpp')}",      
       			type:'post', //数据发送方式  
       			data:{ porppid:"<php>echo $_SESSION['qp_id'];</php>" } ,    
       			async: false ,//同步方式     
       			success: function(objson){
       					  					var html_="";
       					    				var pbook_list = $('#p_list');
       					    				var result = objson.data;
       					    				html_ = html_+'<a style="margin-top:3px;color:#222222;" href="javascript:void(0)" rel="查看所有店铺" id="">';
       					    				html_ = html_+'查看所有店铺</a><br>';
       					    				if(result==null||result=='null'){
       					    					
       					    				}else{
		       					    			for(i=0;i<result.length;i++){
		       					    				html_ = html_+'<a style="margin-top:3px;color:#222222;" href="javascript:void(0)" rel="'+result[i].title+'" id="'+result[i].id+'">';
		       					    				if(result[i].parent_id!=0&&result[i].parent_id!='0'){
		       					    					html_ = html_+"[分]";
		       					    				}else{
		       					    					html_ = html_+"[总]";
		       					    				}
		       					    				html_ = html_+'&nbsp;&nbsp;&nbsp;&nbsp;'+result[i].title+'</a><br>';
			       					    		}
       					    				}
		       					    		if(html_==""){
		       					    			pbook_list.fadeOut("fast");
		       					    			pbook_list.html(html_);
		       					    		}else{
		       					    			pbook_list.html(html_);
		       					    			var position = current_obj.offset();
		       					    			pbook_list.css({"top":(position.top+23)+"px","left":position.left+"px"});
		       					    			pbook_list.fadeIn("fast");
		       					    		}
		       					    		pbook_list.find('a').each( function(i, elm){
		       					    			$(elm).unbind("click");
		       					    			$(elm).bind('click',function(){
		       					    											current_obj.val($(this).attr('rel'));
		       					    											$('#pid').val($(this).attr('id'));
		       					    											pbook_list.fadeOut("fast");
		       					    						});
		       					    		});
	       					    		}
       			});
	});
	
	goPage(current_pno);
});

function tmp_showChart(data_){
	$.kchart({
		chartWidth : 		"700" , //报表宽度
		chartHeight: 		"260" , //报表高度
		title : 			'销售统计图' , //报表名称
		tableWrapperID : 	'stat_wrapper' , //表格数据table所在的html元素的id
		tableID : 			'graph_data' ,  //表格数据ID
		ifTableDisplay:		true,//是否显示生成table，列表方式显示统计数据
		chartWarpperID : 	'chart_wrapper' , //统计图显示位置
		chartStyle : 		'bar' , //统计图样式  取值参见visualize相关参数
		doAfterTableInit:	function(options_){inittablestyle();},
		data:				data_,
		ifChangeXY:			ifChangeXY,
		url : 				"{:U('shanghu://Statis/ajxstatis')}" //ajax获取数据路径
	});
}

function changeChartXY(){
	ifChangeXY = ifChangeXY?false:true;
	goPage(current_pno);
}

function inittablestyle(){
	//alert(1);
    $("tr[overstyle='on']").hover(
      function () {
        $(this).addClass("bg_hover");
      },
      function () {
        $(this).removeClass("bg_hover");
      }
    );
}

function setstatmodel(model_){
	k_changeGroupStyle('stat_model',' ul > li > a ',model_,'active');
	if(model_=='shanghu'){
		//$('#sms_icon_area').css('top' ,$(this).offset().top+16);
		$('#show_quick').css('display' ,'none');
		$('#show_search').css('display' ,'block');
		$('#search_condition_p').css('float' ,'left');
		$('#search_condition_s').css('float' ,'right');
		$('#statmodel').val('shanghu');
		goPage(current_pno);
	}
	if(model_=='goods'){
		$('#show_quick').css('display' ,'none');
		$('#show_search').css('display' ,'block');
		$('#search_condition_p').css('float' ,'right');
		$('#search_condition_s').css('float' ,'left');
		$('#statmodel').val('goods');
		goPage(current_pno);
	}
	if(model_=='quick'){
		$('#show_search').css('display' ,'none');
		$('#show_quick').css('display' ,'block');
	}
}
/**查询数据分页**/
function goPage(pno){
	var statmodel_ = $('#statmodel').val();//统计查询类型 shanghu-按商户统计 goods-按商品统计
	var checkerid_	= $('#pid').val();//对应商户ID
	var gid_ 	= $('#gid').val();//对应商品ID
	var stime_ 	= $('#stime').val();//开始时间
	var etime_ 	= $('#etime').val();//结束时间
	var timeexp_ =$('#timeexp').val();
	var order_ =$('#order').val();
	//alert(checkerid_+"|"+statmodel_);
	tmp_showChart({pno:pno,statmodel:statmodel_,checkerid:checkerid_,gid:gid_,stime:stime_,etime:etime_,order:order_,timeexp:timeexp_});
	current_pno = pno;
}
</script>

    <!--  START CONTENT WRAPPER -->
    <div id="content_wrapper" style="padding: 30px;">
	
      <!--  START PRIMARY CONTENT style="position: relative;"-->
      <div id="primary_content" style="width: 100%;">
      	<style>
			.stat_title{
				float:right;height: 31px; position: relative;padding-top: 11px;
			}
			.stat_title li {
			    display: inline;
			    margin: 0;
			    padding: 0;
			}
			.stat_title a {
			    border-top-left-radius: 2px;
			    border-top-right-radius: 2px;
			    display: block;
			    float: left;
			    font-size: 12px;
			    font-weight: bold;
			    height: 25px;
			    line-height: 25px;
			    margin: 0 5px 0 0;
			    padding: 3px 10px;
			    text-decoration: none;
			}
			.stat_title .active, .stat_title .active:hover {
			    background-color: #D9E9F9;
			    border-left: 1px solid #B6D5F3;
			    border-right: 1px solid #B6D5F3;
			    border-top: 1px solid #B6D5F3;
			    color: #222222;
			}
		</style>
      	<div class='stat_title' id="stat_model">
	        <ul>
	            <li>
	            	<a href="javascript:setstatmodel('shanghu');" rel="shanghu" <php>if($statmodel=='shanghu'){</php>class="active"<php>}</php> >
	            	<img width="20" height="20" style="vertical-align: middle;" src="/Public/shanghu/images/chart_32.png" alt="Stats" class="png_bg">
	            	按店铺统计</a></li>
	             <li>
	            	<a href="javascript:setstatmodel('goods');" rel='goods' <php>if($statmodel=='goods'){</php>class="active"<php>}</php> >
	            	<img width="20" height="20" style="vertical-align: middle;" src="/Public/shanghu/images/chart_32.png" alt="Stats" class="png_bg">
	            	按商品统计</a></li>		
	            <li>
	            	<a href="javascript:setstatmodel('quick');" rel='quick'>
	            	<img width="20" height="20" style="vertical-align: middle;" src="/Public/shanghu/images/chart_32.png" alt="Stats" class="png_bg">
	            	常用统计方式</a></li>
	            
	        </ul>
    	</div>
      
		<h2 style="border-bottom: 2px solid #B6D5F3;">销售数据统计
        	&nbsp;&nbsp;&nbsp;&nbsp;
        	<span style="font-size:12px;">总共卖出：<font style="color: #FF9600;font-family: Arial,Helvetica,sans-serif;font-size: 18px;">{$totalsell}</font>&nbsp;件</span>
        </h2>
        <div class="clear"></div>
       	<!-------- 搜索开始 -------->
		  	<div id="search_div" style="padding: 00px 0;text-align:center;">
				<div id="show_search" style="line-height:35px;text-align:center;display:block;">
					<input id="pno" name="pno" type="hidden" value="1">	
					<input id="statmodel" name="statmodel" type="hidden" value="{$statmodel}"><!-- shanghu-按店铺 goods-按商品 -->	
					<div id="search_condition_1" style="float:left;margin: 0 0px 0px 2px;width: 330px;">
						<div id='search_condition_p' style="float:left;margin: 0px; text-align: center; width: 165px;">
							<span>店铺：</span>
	           				<input type="text" id="pdesc" value="{:getParnterTitle($checkerid,'查看所有店铺')}" class="normal_input" title="选择店铺！" style="width:100px"/>
	            			<input type="hidden" name="pid" id="pid" value="{$checkerid}"/>
	 					</div>
						<div id='search_condition_s' style="float:left;margin: 0px; text-align: center; width: 165px;">
							<span>商品：</span>
							<input type="text" readonly="" onclick="k_pop_syncSearch('gid'
						        													,'goodsdesc'
						        													,'选择商品'
						        													,'/shanghu/index.php/Public/ajxgoods/partner_id/<php>echo $_SESSION['qp_parent_id'];</php>'
						        													,null
						        													,null)" 
						        		  title="选择产品！" value="{$gid|getGoodsTitle}" id="goodsdesc"  class="normal_input" style="width:100px" >
						  	<input type="hidden" id="gid" name="gid" value="{$gid}">
						</div>
					</div>        
					 <div id='search_condition_2' style="float:left;margin: 0 8px;">
						<span>时间：</span>
						<input type="text" id="stime" value="{$stime}" onfocus="rcalendar(this);" class="normal_input" title="选择统计开始时间！" style="width:100px"/>
            		 	~
            		 	<input type="text" id="etime" value="{$etime}" onfocus="rcalendar(this);" class="normal_input" title="选择统计结束时间！" style="width:100px"/>
					</div>
					<div id='search_condition_3' style="float:left;margin: 0 8px;">
						<span>方式：</span>
						<select style="height: 22px; width: 80px;" class="normal_input" id="timeexp">
						   	<option value="month" <eq name="timeexp" value="month">selected</eq>>按月统计</option>
						   	<option value="day" <eq name="timeexp" value="day">selected</eq>>按日统计</option>
						</select>
					</div>
					<div id='search_condition_3' style="float:left;margin: 0px 8px;">
						<span>排序：</span>
						<select style="height: 22px; width: 80px;" class="normal_input" id="order">
						   	<option value="new" <eq name="order" value="new">selected</eq>>最新</option>
					        <option value="up" <eq name="order" value="up">selected</eq>>销售量升</option>
					        <option value="down" <eq name="order" value="down">selected</eq>>销售量降</option>
						</select>
							
					</div>
					<br>
					<input type="button" onclick="goPage(1)" class="btn_b" value="查询" />
			  	</div>
			  	<div id="show_quick" style="line-height:35px;text-align:center;display:none;height: 70px;font-weight: bold;">
						<php>$time_now = time();
			       			//$time_nd_ = date('Y-m-d', time() );
			       			$time_nm_ = date('Y-m',  time() );
			       			//echo $time_nm_;
			       			$time_3m = date('Y-m-d', strtotime("-2 months", paramDate( $time_nm_.'-01' ) ) );
			       			//echo $time_3m;
			       			$time_nm = date('Y-m-d', strtotime("+1 months", paramDate( $time_nm_.'-01' ) ) );
			       			//echo $time_nm;
			       			$time_nm = date('Y-m-d', strtotime("-1 days", paramDate( $time_nm ) ) );
			       			//echo $time_nm;
			       			$time_15d = date('Y-m-d', strtotime("-14 days", time()) );
			       			$time_nd = date('Y-m-d', strtotime("+0 days", time()) );
			       		</php>
			          <div style="float:left;margin:0px;width: 200px;">
			            <img src="/Public/shanghu/images/chart_32.png" height="32" width="32"> 
			            <a href="{:U('shanghu://Statis/index',array('statmodel'=>'goods','stime'=>$time_3m,'etime'=>$time_nm,'timeexp'=>'month'))}" 
			            	title="查看最近3个月商品销售统计数据">近3个月商品销售统计</a>
			          </div>
			          <div style="float:left;margin:0px;width: 200px;">
			            <p><img src="/Public/shanghu/images/chart_32.png" height="32" width="32"> 
			            <a href="{:U('shanghu://Statis/index',array('statmodel'=>'shanghu','stime'=>$time_3m,'etime'=>$time_nm,'timeexp'=>'month'))}"
			            	title="查看最近3个月店铺销售统计数据">近3个月店铺销售统计</a>
			          </div>
			          <div style="float:left;margin:0px;width: 200px;">
			            <img src="/Public/shanghu/images/chart_32.png" height="32" width="32"> 
			            <a href="{:U('shanghu://Statis/index',array('statmodel'=>'goods','stime'=>$time_15d,'etime'=>$time_nd,'timeexp'=>'day'))}"
			            	title="查看最近15天商品销售统计数据">最近15天商品销售统计</a>
			          </div>
			          <div style="float:left;margin:0px;width: 200px;">
			            <img src="/Public/shanghu/images/chart_32.png" height="32" width="32"> 
			            <a href="{:U('shanghu://Statis/index',array('statmodel'=>'shanghu','stime'=>$time_15d,'etime'=>$time_nd,'timeexp'=>'day'))}"
			            	title="查看最近15天店铺销售统计数据">最近15天店铺销售统计</a>
			          </div>
			        </ul>
				</div>
		  	</div>
		  	
		  	<div class="clear"></div>
		  	
		  	<div style="float:right; margin-right: 12px; margin-top: -25px;"><a href="javascript:changeChartXY()">转换统计图XY轴</a></div>
		  	
		  	<div class="clear"></div>
		  	
		  	<!-------- 搜索结束 -------->
  			<div id="chart_wrapper" class="chart_wrapper content" style="height:350px;overflow:hidden;"></div>
  			<div class="clear"></div>
			<div id="stat_wrapper" class="list" style="overflow: auto;"></div>
			
    	<!-- Paginator end -->
      </div>
      <!--  END PRIMARY CONTENT -->
 	  
      <!--  END SIDEBAR -->
    </div><!--  end div #content_wrapper -->
<!--  END CONTENT_WRAPPER -->
<div id="p_list" style="border: 1px solid #C5C5C5;display:none;position: absolute; 
							border-radius: 3px 3px 3px 3px;background-color: #FAFAFA;font-weight: bold;font-size:12px; z-index: 9;line-height: 23px; margin-top: 0px; padding: 5px 10px;width:220px;text-align: left;overflow:hidden;"></div>
  
<include file="../Public/footer_sh.html" />